{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/user/miniconda3/envs/yjq-ml/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from model import OmniAnomaly\n",
    "import numpy as np\n",
    "import sys\n",
    "sys.path.append('../../common/')\n",
    "from evaluator import *\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_dataset(dataset, machine):\n",
    "    folder = os.path.join(\"../../processed\", dataset)\n",
    "    if not os.path.exists(folder):\n",
    "        raise Exception(\"Processed Data not found.\")\n",
    "    loader = []\n",
    "    for file in [\"train\", \"test\", \"labels\"]:\n",
    "        file = machine + \"_\" + file\n",
    "        loader.append(np.load(os.path.join(folder, f\"{file}.npy\")))\n",
    "    ## 准备数据\n",
    "    train_data = loader[0]\n",
    "    test_data = loader[1]\n",
    "    labels = np.zeros((loader[2].shape[0], 1))\n",
    "    for i, row in enumerate(loader[2]):\n",
    "        if np.any(row == 1):\n",
    "            labels[i] = 1   \n",
    "    return (train_data, test_data, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SMD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total datas: 28\n"
     ]
    }
   ],
   "source": [
    "origin_file_list = os.listdir(\"../../data/SMD/interpretation_label\")\n",
    "file_name_list = []\n",
    "for origin_file in origin_file_list:\n",
    "    file_name_list.append(origin_file[:-4])\n",
    "file_name_list.sort()\n",
    "\n",
    "datas = {}\n",
    "for file_name in file_name_list:\n",
    "    train_data, test_data, labels = load_dataset(\"SMD\", file_name)\n",
    "    datas[file_name] = (train_data, test_data, labels)\n",
    "    # print(f\"train_data shape: {train_data.shape}\")\n",
    "    # print(f\"test_data shape: {test_data.shape}\")\n",
    "    # print(f\"labels shape: {labels.shape}\")\n",
    "print(f\"total datas: {len(datas)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "machine-1-1\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(19936, 38)\n",
      "epoch:1/5 step:5 valid_loss:246.2306957244873 train_loss:27.175371170043945\n",
      "epoch:1/5 step:10 valid_loss:235.17684364318848 train_loss:25.974618911743164\n",
      "epoch:1/5 step:15 valid_loss:223.42869758605957 train_loss:24.73590850830078\n",
      "epoch:2/5 step:20 valid_loss:209.82524490356445 train_loss:23.32505226135254\n",
      "epoch:2/5 step:25 valid_loss:192.61836051940918 train_loss:21.548141479492188\n",
      "epoch:2/5 step:30 valid_loss:169.81973266601562 train_loss:19.209394454956055\n",
      "epoch:2/5 step:35 valid_loss:138.87405395507812 train_loss:16.046892166137695\n",
      "epoch:3/5 step:40 valid_loss:99.45907020568848 train_loss:11.937586784362793\n",
      "epoch:3/5 step:45 valid_loss:49.68098258972168 train_loss:6.882422924041748\n",
      "epoch:3/5 step:50 valid_loss:-24.474308013916016 train_loss:-0.7366066575050354\n",
      "epoch:3/5 step:55 valid_loss:-132.1763572692871 train_loss:-12.017929077148438\n",
      "epoch:4/5 step:60 valid_loss:-263.62278747558594 train_loss:-27.026927947998047\n",
      "epoch:4/5 step:65 valid_loss:-313.24245262145996 train_loss:-40.95879364013672\n",
      "epoch:4/5 step:70 valid_loss:-334.615665435791 train_loss:-51.072811126708984\n",
      "epoch:4/5 step:75 valid_loss:-418.18567657470703 train_loss:-59.09197998046875\n",
      "epoch:5/5 step:80 valid_loss:-490.629451751709 train_loss:-66.23927307128906\n",
      "epoch:5/5 step:85 valid_loss:-527.5360107421875 train_loss:-72.05093383789062\n",
      "epoch:5/5 step:90 valid_loss:-467.20385932922363 train_loss:-69.0385513305664\n",
      "score :(28475, 38) recon_mean:(28475, 38) z:(28475, 30)\n",
      "machine-1-2\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16586, 38)\n",
      "epoch:1/5 step:5 valid_loss:177.24720001220703 train_loss:25.644437789916992\n",
      "epoch:1/5 step:10 valid_loss:169.24033546447754 train_loss:24.54218292236328\n",
      "epoch:1/5 step:15 valid_loss:160.38821411132812 train_loss:23.28489112854004\n",
      "epoch:2/5 step:20 valid_loss:150.17376136779785 train_loss:21.87036895751953\n",
      "epoch:2/5 step:25 valid_loss:137.94755935668945 train_loss:20.186220169067383\n",
      "epoch:2/5 step:30 valid_loss:122.59221076965332 train_loss:18.075626373291016\n",
      "epoch:3/5 step:35 valid_loss:102.68204593658447 train_loss:15.341139793395996\n",
      "epoch:3/5 step:40 valid_loss:76.51782512664795 train_loss:11.663765907287598\n",
      "epoch:3/5 step:45 valid_loss:43.253875732421875 train_loss:6.67486572265625\n",
      "epoch:4/5 step:50 valid_loss:4.858884438872337 train_loss:0.5399978756904602\n",
      "epoch:4/5 step:55 valid_loss:-39.51475441455841 train_loss:-6.550070762634277\n",
      "epoch:4/5 step:60 valid_loss:-82.35056400299072 train_loss:-14.491348266601562\n",
      "epoch:5/5 step:65 valid_loss:-128.96578979492188 train_loss:-21.12203598022461\n",
      "epoch:5/5 step:70 valid_loss:-170.18338203430176 train_loss:-27.436370849609375\n",
      "epoch:5/5 step:75 valid_loss:-211.9903049468994 train_loss:-35.309471130371094\n",
      "score :(23690, 38) recon_mean:(23690, 38) z:(23690, 30)\n",
      "machine-1-3\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16592, 38)\n",
      "epoch:1/5 step:5 valid_loss:190.39334678649902 train_loss:27.97392463684082\n",
      "epoch:1/5 step:10 valid_loss:180.47444915771484 train_loss:26.586881637573242\n",
      "epoch:1/5 step:15 valid_loss:171.022066116333 train_loss:25.10207748413086\n",
      "epoch:2/5 step:20 valid_loss:161.12931632995605 train_loss:23.674301147460938\n",
      "epoch:2/5 step:25 valid_loss:150.2426357269287 train_loss:22.107669830322266\n",
      "epoch:2/5 step:30 valid_loss:137.84852027893066 train_loss:20.35133171081543\n",
      "epoch:3/5 step:35 valid_loss:123.83898544311523 train_loss:18.32243537902832\n",
      "epoch:3/5 step:40 valid_loss:107.84605407714844 train_loss:16.043577194213867\n",
      "epoch:3/5 step:45 valid_loss:89.54276943206787 train_loss:13.332698822021484\n",
      "epoch:4/5 step:50 valid_loss:67.59084415435791 train_loss:10.245171546936035\n",
      "epoch:4/5 step:55 valid_loss:41.31036424636841 train_loss:6.690421104431152\n",
      "epoch:4/5 step:60 valid_loss:8.430865466594696 train_loss:1.869592547416687\n",
      "epoch:5/5 step:65 valid_loss:-34.47675895690918 train_loss:-3.829047679901123\n",
      "epoch:5/5 step:70 valid_loss:-91.62280178070068 train_loss:-11.919782638549805\n",
      "epoch:5/5 step:75 valid_loss:-152.4134440422058 train_loss:-22.096782684326172\n",
      "score :(23699, 38) recon_mean:(23699, 38) z:(23699, 30)\n",
      "machine-1-4\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16595, 38)\n",
      "epoch:1/5 step:5 valid_loss:204.22368621826172 train_loss:29.893131256103516\n",
      "epoch:1/5 step:10 valid_loss:196.45626068115234 train_loss:28.75050163269043\n",
      "epoch:1/5 step:15 valid_loss:188.859224319458 train_loss:27.620746612548828\n",
      "epoch:2/5 step:20 valid_loss:180.8079490661621 train_loss:26.4912109375\n",
      "epoch:2/5 step:25 valid_loss:171.53288650512695 train_loss:25.092376708984375\n",
      "epoch:2/5 step:30 valid_loss:160.4502773284912 train_loss:23.645172119140625\n",
      "epoch:3/5 step:35 valid_loss:146.74733352661133 train_loss:21.67924690246582\n",
      "epoch:3/5 step:40 valid_loss:129.82836532592773 train_loss:19.283849716186523\n",
      "epoch:3/5 step:45 valid_loss:109.35562515258789 train_loss:16.41897964477539\n",
      "epoch:4/5 step:50 valid_loss:83.66254043579102 train_loss:12.775246620178223\n",
      "epoch:4/5 step:55 valid_loss:50.82110548019409 train_loss:8.174712181091309\n",
      "epoch:4/5 step:60 valid_loss:11.193089246749878 train_loss:2.663728952407837\n",
      "epoch:5/5 step:65 valid_loss:-37.401540756225586 train_loss:-4.2301249504089355\n",
      "epoch:5/5 step:70 valid_loss:-96.52380084991455 train_loss:-13.426239967346191\n",
      "epoch:5/5 step:75 valid_loss:-153.47518920898438 train_loss:-22.011600494384766\n",
      "score :(23703, 38) recon_mean:(23703, 38) z:(23703, 30)\n",
      "machine-1-5\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16594, 38)\n",
      "epoch:1/5 step:5 valid_loss:184.95119667053223 train_loss:26.53510284423828\n",
      "epoch:1/5 step:10 valid_loss:177.53178787231445 train_loss:25.487897872924805\n",
      "epoch:1/5 step:15 valid_loss:169.86852073669434 train_loss:24.42711067199707\n",
      "epoch:2/5 step:20 valid_loss:161.27289199829102 train_loss:23.245214462280273\n",
      "epoch:2/5 step:25 valid_loss:150.96560859680176 train_loss:21.83515167236328\n",
      "epoch:2/5 step:30 valid_loss:137.98260879516602 train_loss:20.051876068115234\n",
      "epoch:3/5 step:35 valid_loss:121.40376853942871 train_loss:17.83176612854004\n",
      "epoch:3/5 step:40 valid_loss:99.73418235778809 train_loss:14.89013671875\n",
      "epoch:3/5 step:45 valid_loss:72.3458948135376 train_loss:11.169225692749023\n",
      "epoch:4/5 step:50 valid_loss:37.50824165344238 train_loss:6.48255729675293\n",
      "epoch:4/5 step:55 valid_loss:-12.408929824829102 train_loss:-0.18605785071849823\n",
      "epoch:4/5 step:60 valid_loss:-81.49256706237793 train_loss:-9.630727767944336\n",
      "epoch:5/5 step:65 valid_loss:-161.3802890777588 train_loss:-22.68265151977539\n",
      "epoch:5/5 step:70 valid_loss:-216.0372829437256 train_loss:-34.362884521484375\n",
      "epoch:5/5 step:75 valid_loss:-271.6525344848633 train_loss:-42.36497116088867\n",
      "score :(23702, 38) recon_mean:(23702, 38) z:(23702, 30)\n",
      "machine-1-6\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16582, 38)\n",
      "epoch:1/5 step:5 valid_loss:195.59580993652344 train_loss:27.669647216796875\n",
      "epoch:1/5 step:10 valid_loss:186.54857635498047 train_loss:26.46674919128418\n",
      "epoch:1/5 step:15 valid_loss:177.1904239654541 train_loss:25.16179656982422\n",
      "epoch:2/5 step:20 valid_loss:166.92219734191895 train_loss:23.774974822998047\n",
      "epoch:2/5 step:25 valid_loss:154.8596248626709 train_loss:22.17159652709961\n",
      "epoch:2/5 step:30 valid_loss:139.7230930328369 train_loss:20.177650451660156\n",
      "epoch:3/5 step:35 valid_loss:119.93805503845215 train_loss:17.627777099609375\n",
      "epoch:3/5 step:40 valid_loss:94.79503917694092 train_loss:14.47805118560791\n",
      "epoch:3/5 step:45 valid_loss:65.6641321182251 train_loss:10.785004615783691\n",
      "epoch:4/5 step:50 valid_loss:31.3659725189209 train_loss:6.207836151123047\n",
      "epoch:4/5 step:55 valid_loss:-12.92660129070282 train_loss:0.3210020363330841\n",
      "epoch:4/5 step:60 valid_loss:-64.2845458984375 train_loss:-6.674859523773193\n",
      "epoch:5/5 step:65 valid_loss:-117.04106712341309 train_loss:-14.6314115524292\n",
      "epoch:5/5 step:70 valid_loss:-159.50304794311523 train_loss:-22.13025665283203\n",
      "epoch:5/5 step:75 valid_loss:-208.73521423339844 train_loss:-28.865478515625\n",
      "score :(23685, 38) recon_mean:(23685, 38) z:(23685, 30)\n",
      "machine-1-7\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16588, 38)\n",
      "epoch:1/5 step:5 valid_loss:216.43316650390625 train_loss:31.161508560180664\n",
      "epoch:1/5 step:10 valid_loss:206.8375358581543 train_loss:29.63814926147461\n",
      "epoch:1/5 step:15 valid_loss:197.061185836792 train_loss:28.445228576660156\n",
      "epoch:2/5 step:20 valid_loss:186.1012954711914 train_loss:26.798988342285156\n",
      "epoch:2/5 step:25 valid_loss:173.23433113098145 train_loss:25.164264678955078\n",
      "epoch:2/5 step:30 valid_loss:157.40673446655273 train_loss:22.964689254760742\n",
      "epoch:3/5 step:35 valid_loss:136.93961334228516 train_loss:20.130958557128906\n",
      "epoch:3/5 step:40 valid_loss:110.74557876586914 train_loss:16.472204208374023\n",
      "epoch:3/5 step:45 valid_loss:79.62452411651611 train_loss:12.338418960571289\n",
      "epoch:4/5 step:50 valid_loss:46.4385986328125 train_loss:7.574570178985596\n",
      "epoch:4/5 step:55 valid_loss:13.061501681804657 train_loss:2.701610565185547\n",
      "epoch:4/5 step:60 valid_loss:-24.428759694099426 train_loss:-2.3798465728759766\n",
      "epoch:5/5 step:65 valid_loss:-66.4613299369812 train_loss:-8.02798843383789\n",
      "epoch:5/5 step:70 valid_loss:-111.6982774734497 train_loss:-14.469217300415039\n",
      "epoch:5/5 step:75 valid_loss:-155.48480033874512 train_loss:-18.954763412475586\n",
      "score :(23693, 38) recon_mean:(23693, 38) z:(23693, 30)\n",
      "machine-1-8\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16589, 38)\n",
      "epoch:1/5 step:5 valid_loss:186.0068531036377 train_loss:26.517826080322266\n",
      "epoch:1/5 step:10 valid_loss:177.36157035827637 train_loss:25.223888397216797\n",
      "epoch:1/5 step:15 valid_loss:168.18611907958984 train_loss:23.961307525634766\n",
      "epoch:2/5 step:20 valid_loss:157.71320343017578 train_loss:22.534801483154297\n",
      "epoch:2/5 step:25 valid_loss:145.11984062194824 train_loss:20.92808723449707\n",
      "epoch:2/5 step:30 valid_loss:129.36058807373047 train_loss:18.764917373657227\n",
      "epoch:3/5 step:35 valid_loss:109.16062259674072 train_loss:16.04360580444336\n",
      "epoch:3/5 step:40 valid_loss:83.98339462280273 train_loss:12.628748893737793\n",
      "epoch:3/5 step:45 valid_loss:55.28338289260864 train_loss:8.68544864654541\n",
      "epoch:4/5 step:50 valid_loss:20.58284616470337 train_loss:4.080985069274902\n",
      "epoch:4/5 step:55 valid_loss:-19.65530288219452 train_loss:-1.806770920753479\n",
      "epoch:4/5 step:60 valid_loss:-63.03476572036743 train_loss:-8.05964469909668\n",
      "epoch:5/5 step:65 valid_loss:-99.9447193145752 train_loss:-14.489794731140137\n",
      "epoch:5/5 step:70 valid_loss:-136.7170810699463 train_loss:-19.1572322845459\n",
      "epoch:5/5 step:75 valid_loss:-177.63892936706543 train_loss:-24.574804306030273\n",
      "score :(23695, 38) recon_mean:(23695, 38) z:(23695, 30)\n",
      "machine-2-1\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16586, 38)\n",
      "epoch:1/5 step:5 valid_loss:179.64165496826172 train_loss:26.39651107788086\n",
      "epoch:1/5 step:10 valid_loss:171.82375526428223 train_loss:25.18588638305664\n",
      "epoch:1/5 step:15 valid_loss:163.55403900146484 train_loss:23.961774826049805\n",
      "epoch:2/5 step:20 valid_loss:154.33903884887695 train_loss:22.629108428955078\n",
      "epoch:2/5 step:25 valid_loss:143.71811294555664 train_loss:21.059459686279297\n",
      "epoch:2/5 step:30 valid_loss:131.17360305786133 train_loss:19.212793350219727\n",
      "epoch:3/5 step:35 valid_loss:116.1826400756836 train_loss:16.999799728393555\n",
      "epoch:3/5 step:40 valid_loss:98.81211948394775 train_loss:14.361129760742188\n",
      "epoch:3/5 step:45 valid_loss:77.98239421844482 train_loss:11.401735305786133\n",
      "epoch:4/5 step:50 valid_loss:50.76206636428833 train_loss:7.730727195739746\n",
      "epoch:4/5 step:55 valid_loss:15.91296660900116 train_loss:3.0557641983032227\n",
      "epoch:4/5 step:60 valid_loss:-29.36329746246338 train_loss:-2.8403308391571045\n",
      "epoch:5/5 step:65 valid_loss:-81.34340476989746 train_loss:-10.0021390914917\n",
      "epoch:5/5 step:70 valid_loss:-136.5750732421875 train_loss:-18.118927001953125\n",
      "epoch:5/5 step:75 valid_loss:-187.74697875976562 train_loss:-25.23674201965332\n",
      "score :(23690, 38) recon_mean:(23690, 38) z:(23690, 30)\n",
      "machine-2-2\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16590, 38)\n",
      "epoch:1/5 step:5 valid_loss:179.99497413635254 train_loss:25.866533279418945\n",
      "epoch:1/5 step:10 valid_loss:172.18163299560547 train_loss:24.736005783081055\n",
      "epoch:1/5 step:15 valid_loss:163.51111030578613 train_loss:23.572355270385742\n",
      "epoch:2/5 step:20 valid_loss:153.26382064819336 train_loss:22.14787483215332\n",
      "epoch:2/5 step:25 valid_loss:140.6703929901123 train_loss:20.41909408569336\n",
      "epoch:2/5 step:30 valid_loss:124.31973457336426 train_loss:18.22097396850586\n",
      "epoch:3/5 step:35 valid_loss:102.72044944763184 train_loss:15.29153060913086\n",
      "epoch:3/5 step:40 valid_loss:74.01925945281982 train_loss:11.437299728393555\n",
      "epoch:3/5 step:45 valid_loss:36.37667417526245 train_loss:6.323442459106445\n",
      "epoch:4/5 step:50 valid_loss:-15.930719017982483 train_loss:-0.7086230516433716\n",
      "epoch:4/5 step:55 valid_loss:-86.95999240875244 train_loss:-10.70218563079834\n",
      "epoch:4/5 step:60 valid_loss:-169.76750373840332 train_loss:-23.15653419494629\n",
      "epoch:5/5 step:65 valid_loss:-228.84777069091797 train_loss:-34.95164489746094\n",
      "epoch:5/5 step:70 valid_loss:-300.1513977050781 train_loss:-44.24554443359375\n",
      "epoch:5/5 step:75 valid_loss:-353.41141510009766 train_loss:-51.24734878540039\n",
      "score :(23696, 38) recon_mean:(23696, 38) z:(23696, 30)\n",
      "machine-2-3\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16582, 38)\n",
      "epoch:1/5 step:5 valid_loss:186.09753036499023 train_loss:26.815011978149414\n",
      "epoch:1/5 step:10 valid_loss:179.11363792419434 train_loss:25.804811477661133\n",
      "epoch:1/5 step:15 valid_loss:171.77514839172363 train_loss:24.7883243560791\n",
      "epoch:2/5 step:20 valid_loss:163.3676528930664 train_loss:23.618377685546875\n",
      "epoch:2/5 step:25 valid_loss:153.34349822998047 train_loss:22.237010955810547\n",
      "epoch:2/5 step:30 valid_loss:140.88893508911133 train_loss:20.539409637451172\n",
      "epoch:3/5 step:35 valid_loss:124.73382759094238 train_loss:18.358423233032227\n",
      "epoch:3/5 step:40 valid_loss:103.70252132415771 train_loss:15.498034477233887\n",
      "epoch:3/5 step:45 valid_loss:79.08649253845215 train_loss:12.09103012084961\n",
      "epoch:4/5 step:50 valid_loss:47.33246612548828 train_loss:7.857441425323486\n",
      "epoch:4/5 step:55 valid_loss:4.263153403997421 train_loss:2.217366933822632\n",
      "epoch:4/5 step:60 valid_loss:-63.30877208709717 train_loss:-6.509366989135742\n",
      "epoch:5/5 step:65 valid_loss:-155.98719024658203 train_loss:-19.025808334350586\n",
      "epoch:5/5 step:70 valid_loss:-226.3041114807129 train_loss:-29.8760929107666\n",
      "epoch:5/5 step:75 valid_loss:-296.93421173095703 train_loss:-38.52451705932617\n",
      "score :(23685, 38) recon_mean:(23685, 38) z:(23685, 30)\n",
      "machine-2-4\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16583, 38)\n",
      "epoch:1/5 step:5 valid_loss:173.4227409362793 train_loss:25.059438705444336\n",
      "epoch:1/5 step:10 valid_loss:165.6119499206543 train_loss:23.92514991760254\n",
      "epoch:1/5 step:15 valid_loss:157.82388305664062 train_loss:22.843164443969727\n",
      "epoch:2/5 step:20 valid_loss:149.68057441711426 train_loss:21.695209503173828\n",
      "epoch:2/5 step:25 valid_loss:140.63167190551758 train_loss:20.42503547668457\n",
      "epoch:2/5 step:30 valid_loss:130.22579193115234 train_loss:19.02259063720703\n",
      "epoch:3/5 step:35 valid_loss:117.55850982666016 train_loss:17.3030948638916\n",
      "epoch:3/5 step:40 valid_loss:101.48379039764404 train_loss:15.120590209960938\n",
      "epoch:3/5 step:45 valid_loss:81.29189395904541 train_loss:12.342230796813965\n",
      "epoch:4/5 step:50 valid_loss:55.1689395904541 train_loss:8.812295913696289\n",
      "epoch:4/5 step:55 valid_loss:20.817537307739258 train_loss:3.961912155151367\n",
      "epoch:4/5 step:60 valid_loss:-26.63026452064514 train_loss:-2.598602294921875\n",
      "epoch:5/5 step:65 valid_loss:-93.21344661712646 train_loss:-11.892824172973633\n",
      "epoch:5/5 step:70 valid_loss:-165.92471313476562 train_loss:-23.180322647094727\n",
      "epoch:5/5 step:75 valid_loss:-207.15343856811523 train_loss:-31.53450584411621\n",
      "score :(23685, 38) recon_mean:(23685, 38) z:(23685, 30)\n",
      "machine-2-5\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16582, 38)\n",
      "epoch:1/5 step:5 valid_loss:176.96545791625977 train_loss:25.827592849731445\n",
      "epoch:1/5 step:10 valid_loss:168.75352668762207 train_loss:24.5972843170166\n",
      "epoch:1/5 step:15 valid_loss:160.05174446105957 train_loss:23.384235382080078\n",
      "epoch:2/5 step:20 valid_loss:149.92275428771973 train_loss:21.958900451660156\n",
      "epoch:2/5 step:25 valid_loss:137.51194953918457 train_loss:20.170698165893555\n",
      "epoch:2/5 step:30 valid_loss:121.50207710266113 train_loss:17.952518463134766\n",
      "epoch:3/5 step:35 valid_loss:100.27346515655518 train_loss:14.890948295593262\n",
      "epoch:3/5 step:40 valid_loss:72.81561946868896 train_loss:10.829305648803711\n",
      "epoch:3/5 step:45 valid_loss:39.45471668243408 train_loss:5.615108013153076\n",
      "epoch:4/5 step:50 valid_loss:-9.762729823589325 train_loss:-1.3888126611709595\n",
      "epoch:4/5 step:55 valid_loss:-80.74524211883545 train_loss:-10.896098136901855\n",
      "epoch:4/5 step:60 valid_loss:-158.5978488922119 train_loss:-21.77018928527832\n",
      "epoch:5/5 step:65 valid_loss:-205.4308624267578 train_loss:-29.25650405883789\n",
      "epoch:5/5 step:70 valid_loss:-267.76242446899414 train_loss:-35.77730941772461\n",
      "epoch:5/5 step:75 valid_loss:-312.42346954345703 train_loss:-45.615760803222656\n",
      "score :(23685, 38) recon_mean:(23685, 38) z:(23685, 30)\n",
      "machine-2-6\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20121, 38)\n",
      "epoch:1/5 step:5 valid_loss:244.30352020263672 train_loss:27.329662322998047\n",
      "epoch:1/5 step:10 valid_loss:233.79389762878418 train_loss:26.146474838256836\n",
      "epoch:1/5 step:15 valid_loss:223.42029762268066 train_loss:25.061786651611328\n",
      "epoch:2/5 step:20 valid_loss:212.3234748840332 train_loss:23.789554595947266\n",
      "epoch:2/5 step:25 valid_loss:199.6871166229248 train_loss:22.44776725769043\n",
      "epoch:2/5 step:30 valid_loss:184.97312927246094 train_loss:20.818084716796875\n",
      "epoch:2/5 step:35 valid_loss:167.10768699645996 train_loss:18.975433349609375\n",
      "epoch:3/5 step:40 valid_loss:144.6443099975586 train_loss:16.606969833374023\n",
      "epoch:3/5 step:45 valid_loss:115.88121700286865 train_loss:13.552000045776367\n",
      "epoch:3/5 step:50 valid_loss:78.98130655288696 train_loss:9.719752311706543\n",
      "epoch:3/5 step:55 valid_loss:29.645055770874023 train_loss:4.596343517303467\n",
      "epoch:4/5 step:60 valid_loss:-33.328922510147095 train_loss:-2.21895694732666\n",
      "epoch:4/5 step:65 valid_loss:-106.69099617004395 train_loss:-10.812495231628418\n",
      "epoch:4/5 step:70 valid_loss:-179.3663215637207 train_loss:-18.06065559387207\n",
      "epoch:4/5 step:75 valid_loss:-255.46041679382324 train_loss:-27.092031478881836\n",
      "epoch:5/5 step:80 valid_loss:-315.1418647766113 train_loss:-33.92782211303711\n",
      "epoch:5/5 step:85 valid_loss:-386.5595474243164 train_loss:-41.16807556152344\n",
      "epoch:5/5 step:90 valid_loss:-437.9608612060547 train_loss:-46.65684509277344\n",
      "score :(28739, 38) recon_mean:(28739, 38) z:(28739, 30)\n",
      "machine-2-7\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16588, 38)\n",
      "epoch:1/5 step:5 valid_loss:179.56184768676758 train_loss:26.232669830322266\n",
      "epoch:1/5 step:10 valid_loss:172.3049373626709 train_loss:25.188636779785156\n",
      "epoch:1/5 step:15 valid_loss:165.16211891174316 train_loss:24.153602600097656\n",
      "epoch:2/5 step:20 valid_loss:157.4801025390625 train_loss:23.044857025146484\n",
      "epoch:2/5 step:25 valid_loss:148.78748893737793 train_loss:21.81427764892578\n",
      "epoch:2/5 step:30 valid_loss:138.6608600616455 train_loss:20.40628433227539\n",
      "epoch:3/5 step:35 valid_loss:126.38162803649902 train_loss:18.672300338745117\n",
      "epoch:3/5 step:40 valid_loss:110.90512657165527 train_loss:16.57550048828125\n",
      "epoch:3/5 step:45 valid_loss:90.70110607147217 train_loss:13.757110595703125\n",
      "epoch:4/5 step:50 valid_loss:64.02381896972656 train_loss:9.955471992492676\n",
      "epoch:4/5 step:55 valid_loss:31.085166215896606 train_loss:5.116382122039795\n",
      "epoch:4/5 step:60 valid_loss:-11.00936472415924 train_loss:-1.0109095573425293\n",
      "epoch:5/5 step:65 valid_loss:-68.61337375640869 train_loss:-9.126242637634277\n",
      "epoch:5/5 step:70 valid_loss:-144.14082717895508 train_loss:-20.336456298828125\n",
      "epoch:5/5 step:75 valid_loss:-210.68255233764648 train_loss:-30.752668380737305\n",
      "score :(23692, 38) recon_mean:(23692, 38) z:(23692, 30)\n",
      "machine-2-8\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16592, 38)\n",
      "epoch:1/5 step:5 valid_loss:177.11227226257324 train_loss:25.411556243896484\n",
      "epoch:1/5 step:10 valid_loss:167.544340133667 train_loss:24.070209503173828\n",
      "epoch:1/5 step:15 valid_loss:156.8615322113037 train_loss:22.588407516479492\n",
      "epoch:2/5 step:20 valid_loss:144.0374755859375 train_loss:20.83528709411621\n",
      "epoch:2/5 step:25 valid_loss:127.7183723449707 train_loss:18.632463455200195\n",
      "epoch:2/5 step:30 valid_loss:106.27988624572754 train_loss:15.733116149902344\n",
      "epoch:3/5 step:35 valid_loss:77.88977241516113 train_loss:11.873810768127441\n",
      "epoch:3/5 step:40 valid_loss:40.945730686187744 train_loss:6.860145092010498\n",
      "epoch:3/5 step:45 valid_loss:-6.709238231182098 train_loss:0.3448082208633423\n",
      "epoch:4/5 step:50 valid_loss:-68.03108406066895 train_loss:-8.5039644241333\n",
      "epoch:4/5 step:55 valid_loss:-129.85667610168457 train_loss:-18.622888565063477\n",
      "epoch:4/5 step:60 valid_loss:-186.7717399597168 train_loss:-28.958364486694336\n",
      "epoch:5/5 step:65 valid_loss:-237.37003707885742 train_loss:-38.404842376708984\n",
      "epoch:5/5 step:70 valid_loss:-295.1967010498047 train_loss:-47.80071258544922\n",
      "epoch:5/5 step:75 valid_loss:-333.5252456665039 train_loss:-55.08554458618164\n",
      "score :(23699, 38) recon_mean:(23699, 38) z:(23699, 30)\n",
      "machine-2-9\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20106, 38)\n",
      "epoch:1/5 step:5 valid_loss:224.4402027130127 train_loss:25.04346466064453\n",
      "epoch:1/5 step:10 valid_loss:213.49402236938477 train_loss:23.798402786254883\n",
      "epoch:1/5 step:15 valid_loss:202.2861270904541 train_loss:22.563480377197266\n",
      "epoch:2/5 step:20 valid_loss:189.75392150878906 train_loss:21.23885726928711\n",
      "epoch:2/5 step:25 valid_loss:174.766206741333 train_loss:19.647441864013672\n",
      "epoch:2/5 step:30 valid_loss:156.05609321594238 train_loss:17.684171676635742\n",
      "epoch:2/5 step:35 valid_loss:131.53683376312256 train_loss:15.14209270477295\n",
      "epoch:3/5 step:40 valid_loss:98.73103618621826 train_loss:11.756428718566895\n",
      "epoch:3/5 step:45 valid_loss:55.83816051483154 train_loss:7.137646198272705\n",
      "epoch:3/5 step:50 valid_loss:-0.03847964107990265 train_loss:0.9921138286590576\n",
      "epoch:3/5 step:55 valid_loss:-63.08875250816345 train_loss:-7.289185047149658\n",
      "epoch:4/5 step:60 valid_loss:-122.93085384368896 train_loss:-16.948877334594727\n",
      "epoch:4/5 step:65 valid_loss:-168.67478942871094 train_loss:-25.27814483642578\n",
      "epoch:4/5 step:70 valid_loss:-223.85357666015625 train_loss:-33.3399658203125\n",
      "epoch:4/5 step:75 valid_loss:-292.11618423461914 train_loss:-41.563270568847656\n",
      "epoch:5/5 step:80 valid_loss:-328.31880950927734 train_loss:-49.37721633911133\n",
      "epoch:5/5 step:85 valid_loss:-391.34261322021484 train_loss:-55.101619720458984\n",
      "epoch:5/5 step:90 valid_loss:-456.59579277038574 train_loss:-60.37868881225586\n",
      "score :(28718, 38) recon_mean:(28718, 38) z:(28718, 30)\n",
      "machine-3-1\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20090, 38)\n",
      "epoch:1/5 step:5 valid_loss:235.17582321166992 train_loss:26.313438415527344\n",
      "epoch:1/5 step:10 valid_loss:222.2890911102295 train_loss:24.900409698486328\n",
      "epoch:1/5 step:15 valid_loss:209.13085174560547 train_loss:23.466169357299805\n",
      "epoch:2/5 step:20 valid_loss:194.48573684692383 train_loss:21.890287399291992\n",
      "epoch:2/5 step:25 valid_loss:177.41987991333008 train_loss:20.09632110595703\n",
      "epoch:2/5 step:30 valid_loss:156.83858108520508 train_loss:17.93879508972168\n",
      "epoch:2/5 step:35 valid_loss:131.32820892333984 train_loss:15.297281265258789\n",
      "epoch:3/5 step:40 valid_loss:99.0645751953125 train_loss:11.97027587890625\n",
      "epoch:3/5 step:45 valid_loss:54.51128530502319 train_loss:7.532118797302246\n",
      "epoch:3/5 step:50 valid_loss:-7.633814632892609 train_loss:1.2699300050735474\n",
      "epoch:3/5 step:55 valid_loss:-91.00126266479492 train_loss:-7.124518871307373\n",
      "epoch:4/5 step:60 valid_loss:-190.32857704162598 train_loss:-17.743350982666016\n",
      "epoch:4/5 step:65 valid_loss:-273.4849605560303 train_loss:-27.909616470336914\n",
      "epoch:4/5 step:70 valid_loss:-331.553466796875 train_loss:-36.99969482421875\n",
      "epoch:4/5 step:75 valid_loss:-393.11828231811523 train_loss:-43.57209396362305\n",
      "epoch:5/5 step:80 valid_loss:-461.5527801513672 train_loss:-50.50397491455078\n",
      "epoch:5/5 step:85 valid_loss:-511.06644439697266 train_loss:-55.98155212402344\n",
      "epoch:5/5 step:90 valid_loss:-531.8952522277832 train_loss:-60.408695220947266\n",
      "score :(28696, 38) recon_mean:(28696, 38) z:(28696, 30)\n",
      "machine-3-10\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16585, 38)\n",
      "epoch:1/5 step:5 valid_loss:197.1358585357666 train_loss:28.869577407836914\n",
      "epoch:1/5 step:10 valid_loss:186.9583683013916 train_loss:27.34370994567871\n",
      "epoch:1/5 step:15 valid_loss:176.57011222839355 train_loss:25.904008865356445\n",
      "epoch:2/5 step:20 valid_loss:165.21246528625488 train_loss:24.272151947021484\n",
      "epoch:2/5 step:25 valid_loss:151.90899085998535 train_loss:22.489330291748047\n",
      "epoch:2/5 step:30 valid_loss:135.6077823638916 train_loss:20.228750228881836\n",
      "epoch:3/5 step:35 valid_loss:115.24474716186523 train_loss:17.47343635559082\n",
      "epoch:3/5 step:40 valid_loss:89.22589111328125 train_loss:14.061929702758789\n",
      "epoch:3/5 step:45 valid_loss:55.16033601760864 train_loss:9.633173942565918\n",
      "epoch:4/5 step:50 valid_loss:13.968372464179993 train_loss:4.248924255371094\n",
      "epoch:4/5 step:55 valid_loss:-37.13015031814575 train_loss:-3.234387159347534\n",
      "epoch:4/5 step:60 valid_loss:-106.18800830841064 train_loss:-11.663034439086914\n",
      "epoch:5/5 step:65 valid_loss:-167.0936222076416 train_loss:-21.18242835998535\n",
      "epoch:5/5 step:70 valid_loss:-213.95272254943848 train_loss:-29.48336410522461\n",
      "epoch:5/5 step:75 valid_loss:-271.5359802246094 train_loss:-34.73424530029297\n",
      "score :(23689, 38) recon_mean:(23689, 38) z:(23689, 30)\n",
      "machine-3-11\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20087, 38)\n",
      "epoch:1/5 step:5 valid_loss:271.14713287353516 train_loss:29.94417953491211\n",
      "epoch:1/5 step:10 valid_loss:259.979793548584 train_loss:28.73687744140625\n",
      "epoch:1/5 step:15 valid_loss:248.85553359985352 train_loss:27.53060531616211\n",
      "epoch:2/5 step:20 valid_loss:236.47735214233398 train_loss:26.2106876373291\n",
      "epoch:2/5 step:25 valid_loss:221.94918632507324 train_loss:24.65231704711914\n",
      "epoch:2/5 step:30 valid_loss:204.55597114562988 train_loss:22.816253662109375\n",
      "epoch:2/5 step:35 valid_loss:183.35033226013184 train_loss:20.601362228393555\n",
      "epoch:3/5 step:40 valid_loss:157.08349990844727 train_loss:17.857311248779297\n",
      "epoch:3/5 step:45 valid_loss:127.84231662750244 train_loss:14.753031730651855\n",
      "epoch:3/5 step:50 valid_loss:95.69521522521973 train_loss:11.38270378112793\n",
      "epoch:3/5 step:55 valid_loss:58.40638971328735 train_loss:7.340760231018066\n",
      "epoch:4/5 step:60 valid_loss:13.593518674373627 train_loss:2.418128490447998\n",
      "epoch:4/5 step:65 valid_loss:-31.69500160217285 train_loss:-2.8029375076293945\n",
      "epoch:4/5 step:70 valid_loss:-83.17631912231445 train_loss:-8.606194496154785\n",
      "epoch:4/5 step:75 valid_loss:-134.95988941192627 train_loss:-14.888408660888672\n",
      "epoch:5/5 step:80 valid_loss:-200.33700370788574 train_loss:-22.27398109436035\n",
      "epoch:5/5 step:85 valid_loss:-257.9148998260498 train_loss:-29.446380615234375\n",
      "epoch:5/5 step:90 valid_loss:-324.4641647338867 train_loss:-36.770992279052734\n",
      "score :(28692, 38) recon_mean:(28692, 38) z:(28692, 30)\n",
      "machine-3-2\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16592, 38)\n",
      "epoch:1/5 step:5 valid_loss:192.55460166931152 train_loss:28.494770050048828\n",
      "epoch:1/5 step:10 valid_loss:183.20231246948242 train_loss:27.128671646118164\n",
      "epoch:1/5 step:15 valid_loss:172.79369354248047 train_loss:25.525726318359375\n",
      "epoch:2/5 step:20 valid_loss:160.69206047058105 train_loss:23.78632354736328\n",
      "epoch:2/5 step:25 valid_loss:146.08296012878418 train_loss:21.699541091918945\n",
      "epoch:2/5 step:30 valid_loss:128.15394592285156 train_loss:19.04743766784668\n",
      "epoch:3/5 step:35 valid_loss:106.66268920898438 train_loss:15.84215259552002\n",
      "epoch:3/5 step:40 valid_loss:81.45544052124023 train_loss:12.125276565551758\n",
      "epoch:3/5 step:45 valid_loss:49.540863037109375 train_loss:7.568098068237305\n",
      "epoch:4/5 step:50 valid_loss:11.398181021213531 train_loss:2.164870500564575\n",
      "epoch:4/5 step:55 valid_loss:-33.40710890293121 train_loss:-4.753138542175293\n",
      "epoch:4/5 step:60 valid_loss:-78.8973708152771 train_loss:-12.698779106140137\n",
      "epoch:5/5 step:65 valid_loss:-133.6924066543579 train_loss:-20.372140884399414\n",
      "epoch:5/5 step:70 valid_loss:-179.76055335998535 train_loss:-27.109403610229492\n",
      "epoch:5/5 step:75 valid_loss:-220.7613010406494 train_loss:-34.46084976196289\n",
      "score :(23699, 38) recon_mean:(23699, 38) z:(23699, 30)\n",
      "machine-3-3\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16593, 38)\n",
      "epoch:1/5 step:5 valid_loss:202.04745483398438 train_loss:29.608713150024414\n",
      "epoch:1/5 step:10 valid_loss:194.10223770141602 train_loss:28.43441390991211\n",
      "epoch:1/5 step:15 valid_loss:185.72575759887695 train_loss:27.23298454284668\n",
      "epoch:2/5 step:20 valid_loss:176.13745498657227 train_loss:25.912776947021484\n",
      "epoch:2/5 step:25 valid_loss:164.78846549987793 train_loss:24.320148468017578\n",
      "epoch:2/5 step:30 valid_loss:151.2192554473877 train_loss:22.447290420532227\n",
      "epoch:3/5 step:35 valid_loss:134.5996913909912 train_loss:20.165111541748047\n",
      "epoch:3/5 step:40 valid_loss:113.91185188293457 train_loss:17.228534698486328\n",
      "epoch:3/5 step:45 valid_loss:88.48960304260254 train_loss:13.659445762634277\n",
      "epoch:4/5 step:50 valid_loss:58.17089796066284 train_loss:9.326078414916992\n",
      "epoch:4/5 step:55 valid_loss:20.123482823371887 train_loss:4.107219219207764\n",
      "epoch:4/5 step:60 valid_loss:-31.18480134010315 train_loss:-2.765488862991333\n",
      "epoch:5/5 step:65 valid_loss:-90.3199577331543 train_loss:-10.543204307556152\n",
      "epoch:5/5 step:70 valid_loss:-146.04255485534668 train_loss:-18.379472732543945\n",
      "epoch:5/5 step:75 valid_loss:-196.07282257080078 train_loss:-24.46308135986328\n",
      "score :(23699, 38) recon_mean:(23699, 38) z:(23699, 30)\n",
      "machine-3-4\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16581, 38)\n",
      "epoch:1/5 step:5 valid_loss:198.98809623718262 train_loss:28.678091049194336\n",
      "epoch:1/5 step:10 valid_loss:190.12637519836426 train_loss:27.390384674072266\n",
      "epoch:1/5 step:15 valid_loss:181.30252647399902 train_loss:26.11924934387207\n",
      "epoch:2/5 step:20 valid_loss:171.75955390930176 train_loss:24.801786422729492\n",
      "epoch:2/5 step:25 valid_loss:160.788667678833 train_loss:23.27766990661621\n",
      "epoch:2/5 step:30 valid_loss:147.84018325805664 train_loss:21.498065948486328\n",
      "epoch:3/5 step:35 valid_loss:132.23043251037598 train_loss:19.3922119140625\n",
      "epoch:3/5 step:40 valid_loss:113.04756736755371 train_loss:16.718366622924805\n",
      "epoch:3/5 step:45 valid_loss:90.18115425109863 train_loss:13.565263748168945\n",
      "epoch:4/5 step:50 valid_loss:62.80207347869873 train_loss:9.834376335144043\n",
      "epoch:4/5 step:55 valid_loss:28.69028401374817 train_loss:5.168178558349609\n",
      "epoch:4/5 step:60 valid_loss:-15.430248498916626 train_loss:-0.8183133602142334\n",
      "epoch:5/5 step:65 valid_loss:-71.1008243560791 train_loss:-8.428112030029297\n",
      "epoch:5/5 step:70 valid_loss:-127.65089988708496 train_loss:-17.15896987915039\n",
      "epoch:5/5 step:75 valid_loss:-171.86402893066406 train_loss:-23.955928802490234\n",
      "score :(23683, 38) recon_mean:(23683, 38) z:(23683, 30)\n",
      "machine-3-5\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(16583, 38)\n",
      "epoch:1/5 step:5 valid_loss:191.31736183166504 train_loss:27.696998596191406\n",
      "epoch:1/5 step:10 valid_loss:183.11765670776367 train_loss:26.508703231811523\n",
      "epoch:1/5 step:15 valid_loss:174.1554012298584 train_loss:25.285783767700195\n",
      "epoch:2/5 step:20 valid_loss:163.79846954345703 train_loss:23.82514762878418\n",
      "epoch:2/5 step:25 valid_loss:151.1033592224121 train_loss:22.095565795898438\n",
      "epoch:2/5 step:30 valid_loss:134.8504524230957 train_loss:19.861337661743164\n",
      "epoch:3/5 step:35 valid_loss:112.92556571960449 train_loss:16.943153381347656\n",
      "epoch:3/5 step:40 valid_loss:82.46654415130615 train_loss:12.887959480285645\n",
      "epoch:3/5 step:45 valid_loss:39.86335372924805 train_loss:7.164560317993164\n",
      "epoch:4/5 step:50 valid_loss:-18.43661642074585 train_loss:-0.5583192110061646\n",
      "epoch:4/5 step:55 valid_loss:-89.78037548065186 train_loss:-10.032228469848633\n",
      "epoch:4/5 step:60 valid_loss:-166.54592323303223 train_loss:-19.884639739990234\n",
      "epoch:5/5 step:65 valid_loss:-218.0966739654541 train_loss:-26.36209487915039\n",
      "epoch:5/5 step:70 valid_loss:-261.3211250305176 train_loss:-34.039791107177734\n",
      "epoch:5/5 step:75 valid_loss:-317.5318717956543 train_loss:-40.53891372680664\n",
      "score :(23687, 38) recon_mean:(23687, 38) z:(23687, 30)\n",
      "machine-3-6\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20109, 38)\n",
      "epoch:1/5 step:5 valid_loss:249.4473762512207 train_loss:27.9024600982666\n",
      "epoch:1/5 step:10 valid_loss:236.17687797546387 train_loss:26.428117752075195\n",
      "epoch:1/5 step:15 valid_loss:222.57970428466797 train_loss:24.999311447143555\n",
      "epoch:2/5 step:20 valid_loss:207.2330265045166 train_loss:23.309438705444336\n",
      "epoch:2/5 step:25 valid_loss:189.0661964416504 train_loss:21.41224479675293\n",
      "epoch:2/5 step:30 valid_loss:166.6789493560791 train_loss:19.043180465698242\n",
      "epoch:2/5 step:35 valid_loss:139.1236753463745 train_loss:16.1291446685791\n",
      "epoch:3/5 step:40 valid_loss:106.63647842407227 train_loss:12.577615737915039\n",
      "epoch:3/5 step:45 valid_loss:70.4542727470398 train_loss:8.880110740661621\n",
      "epoch:3/5 step:50 valid_loss:24.32781994342804 train_loss:3.857579231262207\n",
      "epoch:3/5 step:55 valid_loss:-34.74032950401306 train_loss:-2.4784984588623047\n",
      "epoch:4/5 step:60 valid_loss:-112.48320198059082 train_loss:-10.439083099365234\n",
      "epoch:4/5 step:65 valid_loss:-188.24669647216797 train_loss:-19.580690383911133\n",
      "epoch:4/5 step:70 valid_loss:-266.9560966491699 train_loss:-28.229339599609375\n",
      "epoch:4/5 step:75 valid_loss:-328.6316146850586 train_loss:-35.18552017211914\n",
      "epoch:5/5 step:80 valid_loss:-383.62671661376953 train_loss:-40.71977996826172\n",
      "epoch:5/5 step:85 valid_loss:-451.9941062927246 train_loss:-48.20861053466797\n",
      "epoch:5/5 step:90 valid_loss:-497.8285713195801 train_loss:-54.49152374267578\n",
      "score :(28722, 38) recon_mean:(28722, 38) z:(28722, 30)\n",
      "machine-3-7\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20094, 38)\n",
      "epoch:1/5 step:5 valid_loss:285.8640880584717 train_loss:31.42736053466797\n",
      "epoch:1/5 step:10 valid_loss:272.6313819885254 train_loss:29.888019561767578\n",
      "epoch:1/5 step:15 valid_loss:259.0696716308594 train_loss:28.50600814819336\n",
      "epoch:2/5 step:20 valid_loss:244.12408256530762 train_loss:26.93802833557129\n",
      "epoch:2/5 step:25 valid_loss:226.58599853515625 train_loss:25.003053665161133\n",
      "epoch:2/5 step:30 valid_loss:204.8738250732422 train_loss:22.89008331298828\n",
      "epoch:2/5 step:35 valid_loss:177.25490188598633 train_loss:19.99859046936035\n",
      "epoch:3/5 step:40 valid_loss:143.44557666778564 train_loss:16.516754150390625\n",
      "epoch:3/5 step:45 valid_loss:104.41362571716309 train_loss:12.502487182617188\n",
      "epoch:3/5 step:50 valid_loss:60.738544940948486 train_loss:7.834316253662109\n",
      "epoch:3/5 step:55 valid_loss:13.57763260602951 train_loss:2.9519121646881104\n",
      "epoch:4/5 step:60 valid_loss:-48.64361381530762 train_loss:-3.55639910697937\n",
      "epoch:4/5 step:65 valid_loss:-107.47481632232666 train_loss:-11.042526245117188\n",
      "epoch:4/5 step:70 valid_loss:-164.95012664794922 train_loss:-17.430194854736328\n",
      "epoch:4/5 step:75 valid_loss:-228.1483554840088 train_loss:-23.54085922241211\n",
      "epoch:5/5 step:80 valid_loss:-298.88084411621094 train_loss:-31.529447555541992\n",
      "epoch:5/5 step:85 valid_loss:-345.4301643371582 train_loss:-38.21435546875\n",
      "epoch:5/5 step:90 valid_loss:-400.32251358032227 train_loss:-42.95613098144531\n",
      "score :(28701, 38) recon_mean:(28701, 38) z:(28701, 30)\n",
      "machine-3-8\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20093, 38)\n",
      "epoch:1/5 step:5 valid_loss:237.16633987426758 train_loss:26.458436965942383\n",
      "epoch:1/5 step:10 valid_loss:227.29358673095703 train_loss:25.3708438873291\n",
      "epoch:1/5 step:15 valid_loss:217.949068069458 train_loss:24.32056999206543\n",
      "epoch:2/5 step:20 valid_loss:208.0144214630127 train_loss:23.244413375854492\n",
      "epoch:2/5 step:25 valid_loss:196.525541305542 train_loss:22.01655387878418\n",
      "epoch:2/5 step:30 valid_loss:182.96896743774414 train_loss:20.590587615966797\n",
      "epoch:2/5 step:35 valid_loss:166.7219295501709 train_loss:18.87540054321289\n",
      "epoch:3/5 step:40 valid_loss:146.5416316986084 train_loss:16.73906898498535\n",
      "epoch:3/5 step:45 valid_loss:120.84838008880615 train_loss:14.057042121887207\n",
      "epoch:3/5 step:50 valid_loss:87.7200403213501 train_loss:10.617528915405273\n",
      "epoch:3/5 step:55 valid_loss:41.81873321533203 train_loss:5.961556434631348\n",
      "epoch:4/5 step:60 valid_loss:-27.5131676197052 train_loss:-1.0470741987228394\n",
      "epoch:4/5 step:65 valid_loss:-126.55278205871582 train_loss:-11.433869361877441\n",
      "epoch:4/5 step:70 valid_loss:-218.43450832366943 train_loss:-24.76823616027832\n",
      "epoch:4/5 step:75 valid_loss:-281.1749105453491 train_loss:-38.34548568725586\n",
      "epoch:5/5 step:80 valid_loss:-346.9261474609375 train_loss:-46.26249313354492\n",
      "epoch:5/5 step:85 valid_loss:-422.2920706272125 train_loss:-54.83066177368164\n",
      "epoch:5/5 step:90 valid_loss:-481.9232530593872 train_loss:-58.943328857421875\n",
      "score :(28700, 38) recon_mean:(28700, 38) z:(28700, 30)\n",
      "machine-3-9\n",
      "self._valid_step_freq:5\n",
      "AE_layer 38 30 16 16\n",
      "AE_layer 30 38 16 16\n",
      "(20100, 38)\n",
      "epoch:1/5 step:5 valid_loss:245.11647987365723 train_loss:27.24114227294922\n",
      "epoch:1/5 step:10 valid_loss:234.2516918182373 train_loss:26.05840301513672\n",
      "epoch:1/5 step:15 valid_loss:223.26550674438477 train_loss:24.89467430114746\n",
      "epoch:2/5 step:20 valid_loss:211.02339553833008 train_loss:23.600963592529297\n",
      "epoch:2/5 step:25 valid_loss:196.71900939941406 train_loss:22.086894989013672\n",
      "epoch:2/5 step:30 valid_loss:179.28059196472168 train_loss:20.275035858154297\n",
      "epoch:2/5 step:35 valid_loss:157.47061157226562 train_loss:18.014385223388672\n",
      "epoch:3/5 step:40 valid_loss:130.11281967163086 train_loss:15.185999870300293\n",
      "epoch:3/5 step:45 valid_loss:95.49375438690186 train_loss:11.587361335754395\n",
      "epoch:3/5 step:50 valid_loss:51.16274309158325 train_loss:7.066650390625\n",
      "epoch:3/5 step:55 valid_loss:-5.123779460787773 train_loss:1.3555254936218262\n",
      "epoch:4/5 step:60 valid_loss:-76.52697038650513 train_loss:-6.00599479675293\n",
      "epoch:4/5 step:65 valid_loss:-157.31738662719727 train_loss:-14.88177490234375\n",
      "epoch:4/5 step:70 valid_loss:-228.3869800567627 train_loss:-23.799259185791016\n",
      "epoch:4/5 step:75 valid_loss:-302.33173179626465 train_loss:-32.460689544677734\n",
      "epoch:5/5 step:80 valid_loss:-363.0872917175293 train_loss:-39.3909912109375\n",
      "epoch:5/5 step:85 valid_loss:-410.30216217041016 train_loss:-45.50848388671875\n",
      "epoch:5/5 step:90 valid_loss:-462.94399642944336 train_loss:-51.3015022277832\n",
      "score :(28709, 38) recon_mean:(28709, 38) z:(28709, 30)\n"
     ]
    }
   ],
   "source": [
    "results = {}\n",
    "for machine in file_name_list:\n",
    "        print(machine)\n",
    "        train_data,test_data, labels = datas[machine]\n",
    "        model = OmniAnomaly(x_dims=train_data.shape[1], z_dims=30, window_size=5,max_epochs=5,  batch_size=1024 )\n",
    "        model.fit([train_data])\n",
    "        score,_,_,_= model.predict(test_data)\n",
    "        anomaly_score = -np.mean(score, axis=1)\n",
    "        result = bf_search(score=anomaly_score.squeeze(), label=labels[:-4].squeeze(), verbose=False)\n",
    "        results[machine] = result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "precision mean: 0.9382\n",
      "recall mean: 0.8993\n",
      "f1 mean: 0.9059\n",
      "f1* mean: 0.9183\n"
     ]
    }
   ],
   "source": [
    "f1_scores = [item['f1-score'] for item in list(results.values())]\n",
    "precisions = [item['precision'] for item in list(results.values())]\n",
    "recalls = [item['recall'] for item in list(results.values())]\n",
    "TNs = [item['TN'] for item in list(results.values())]\n",
    "TPs = [item['TP'] for item in list(results.values())]\n",
    "FNs = [item['FN'] for item in list(results.values())]\n",
    "FPs = [item['FP'] for item in list(results.values())]\n",
    "f1_mean = round(np.mean(f1_scores).item(),4)\n",
    "precision_mean = round(np.mean(precisions),4)\n",
    "recall_mean = round(np.mean(recalls),4)\n",
    "f1_star = round(2 * precision_mean * recall_mean / (precision_mean + recall_mean + 0.00001),4)\n",
    "print(f\"precision mean: {precision_mean}\")\n",
    "print(f\"recall mean: {recall_mean}\")\n",
    "print(f\"f1 mean: {f1_mean}\")\n",
    "print(f\"f1* mean: {f1_star}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SMAP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "origin_file_list = os.listdir(\"../../processed/SMAP\")\n",
    "file_name_set = set()\n",
    "for origin_file in origin_file_list:\n",
    "    file_name_set.add(origin_file.split(\"_\")[0])\n",
    "file_name_list = list(file_name_set)\n",
    "file_name_list.sort()\n",
    "datas = {}\n",
    "for file_name in file_name_list:\n",
    "    train_data, test_data, labels = load_dataset(\"SMAP\", file_name)\n",
    "    datas[file_name] = (train_data, test_data, labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8623, 25) recon_mean:(8623, 25) z:(8623, 3)\n",
      "A-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7897, 25) recon_mean:(7897, 25) z:(7897, 3)\n",
      "A-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8188, 25) recon_mean:(8188, 25) z:(8188, 3)\n",
      "A-4\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8063, 25) recon_mean:(8063, 25) z:(8063, 3)\n",
      "A-5\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(4676, 25) recon_mean:(4676, 25) z:(4676, 3)\n",
      "A-6\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(4436, 25) recon_mean:(4436, 25) z:(4436, 3)\n",
      "A-7\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8614, 25) recon_mean:(8614, 25) z:(8614, 3)\n",
      "A-8\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8358, 25) recon_mean:(8358, 25) z:(8358, 3)\n",
      "A-9\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8417, 25) recon_mean:(8417, 25) z:(8417, 3)\n",
      "B-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8027, 25) recon_mean:(8027, 25) z:(8027, 3)\n",
      "D-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8492, 25) recon_mean:(8492, 25) z:(8492, 3)\n",
      "D-11\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7414, 25) recon_mean:(7414, 25) z:(7414, 3)\n",
      "D-12\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7901, 25) recon_mean:(7901, 25) z:(7901, 3)\n",
      "D-13\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7646, 25) recon_mean:(7646, 25) z:(7646, 3)\n",
      "D-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8578, 25) recon_mean:(8578, 25) z:(8578, 3)\n",
      "D-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8623, 25) recon_mean:(8623, 25) z:(8623, 3)\n",
      "D-4\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8456, 25) recon_mean:(8456, 25) z:(8456, 3)\n",
      "D-5\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7611, 25) recon_mean:(7611, 25) z:(7611, 3)\n",
      "D-6\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7867, 25) recon_mean:(7867, 25) z:(7867, 3)\n",
      "D-7\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7625, 25) recon_mean:(7625, 25) z:(7625, 3)\n",
      "D-8\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7857, 25) recon_mean:(7857, 25) z:(7857, 3)\n",
      "D-9\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7389, 25) recon_mean:(7389, 25) z:(7389, 3)\n",
      "E-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8499, 25) recon_mean:(8499, 25) z:(8499, 3)\n",
      "E-10\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8488, 25) recon_mean:(8488, 25) z:(8488, 3)\n",
      "E-11\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8497, 25) recon_mean:(8497, 25) z:(8497, 3)\n",
      "E-12\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8495, 25) recon_mean:(8495, 25) z:(8495, 3)\n",
      "E-13\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8623, 25) recon_mean:(8623, 25) z:(8623, 3)\n",
      "E-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8515, 25) recon_mean:(8515, 25) z:(8515, 3)\n",
      "E-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8290, 25) recon_mean:(8290, 25) z:(8290, 3)\n",
      "E-4\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8337, 25) recon_mean:(8337, 25) z:(8337, 3)\n",
      "E-5\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8277, 25) recon_mean:(8277, 25) z:(8277, 3)\n",
      "E-6\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8283, 25) recon_mean:(8283, 25) z:(8283, 3)\n",
      "E-7\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8293, 25) recon_mean:(8293, 25) z:(8293, 3)\n",
      "E-8\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8515, 25) recon_mean:(8515, 25) z:(8515, 3)\n",
      "E-9\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8285, 25) recon_mean:(8285, 25) z:(8285, 3)\n",
      "F-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8567, 25) recon_mean:(8567, 25) z:(8567, 3)\n",
      "F-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8609, 25) recon_mean:(8609, 25) z:(8609, 3)\n",
      "F-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8359, 25) recon_mean:(8359, 25) z:(8359, 3)\n",
      "G-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8452, 25) recon_mean:(8452, 25) z:(8452, 3)\n",
      "G-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7344, 25) recon_mean:(7344, 25) z:(7344, 3)\n",
      "G-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7890, 25) recon_mean:(7890, 25) z:(7890, 3)\n",
      "G-4\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7615, 25) recon_mean:(7615, 25) z:(7615, 3)\n",
      "G-6\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8623, 25) recon_mean:(8623, 25) z:(8623, 3)\n",
      "G-7\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8012, 25) recon_mean:(8012, 25) z:(8012, 3)\n",
      "P-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8488, 25) recon_mean:(8488, 25) z:(8488, 3)\n",
      "P-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8192, 25) recon_mean:(8192, 25) z:(8192, 3)\n",
      "P-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8476, 25) recon_mean:(8476, 25) z:(8476, 3)\n",
      "P-4\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7766, 25) recon_mean:(7766, 25) z:(7766, 3)\n",
      "P-7\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8054, 25) recon_mean:(8054, 25) z:(8054, 3)\n",
      "R-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7227, 25) recon_mean:(7227, 25) z:(7227, 3)\n",
      "S-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(7314, 25) recon_mean:(7314, 25) z:(7314, 3)\n",
      "T-1\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8595, 25) recon_mean:(8595, 25) z:(8595, 3)\n",
      "T-2\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8608, 25) recon_mean:(8608, 25) z:(8608, 3)\n",
      "T-3\n",
      "self._valid_step_freq:20\n",
      "AE_layer 25 3 16 16\n",
      "AE_layer 3 25 16 16\n",
      "score :(8562, 25) recon_mean:(8562, 25) z:(8562, 3)\n"
     ]
    }
   ],
   "source": [
    "results = {}\n",
    "for machine in file_name_list:\n",
    "        print(machine)\n",
    "        train_data,test_data, labels = datas[machine]\n",
    "        model = OmniAnomaly(x_dims=train_data.shape[1],  window_size=18, max_epochs=5, valid_step_frep=20, batch_size=256)\n",
    "        model.fit([train_data])\n",
    "        score,_,_,_= model.predict(test_data)\n",
    "        anomaly_score = -np.mean(score, axis=1)\n",
    "        result = bf_search(score=anomaly_score.squeeze(), label=labels[:-17].squeeze(), verbose=False)\n",
    "        results[machine] = result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "precision mean: 0.763\n",
      "recall mean: 0.9129\n",
      "f1 mean: 0.7955\n",
      "f1* mean: 0.8312\n"
     ]
    }
   ],
   "source": [
    "f1_scores = [item['f1-score'] for item in list(results.values())]\n",
    "precisions = [item['precision'] for item in list(results.values())]\n",
    "recalls = [item['recall'] for item in list(results.values())]\n",
    "TNs = [item['TN'] for item in list(results.values())]\n",
    "TPs = [item['TP'] for item in list(results.values())]\n",
    "FNs = [item['FN'] for item in list(results.values())]\n",
    "FPs = [item['FP'] for item in list(results.values())]\n",
    "f1_mean = round(np.mean(f1_scores).item(),4)\n",
    "precision_mean = round(np.mean(precisions),4)\n",
    "recall_mean = round(np.mean(recalls),4)\n",
    "f1_star = round(2 * precision_mean * recall_mean / (precision_mean + recall_mean + 0.00001),4)\n",
    "print(f\"precision mean: {precision_mean}\")\n",
    "print(f\"recall mean: {recall_mean}\")\n",
    "print(f\"f1 mean: {f1_mean}\")\n",
    "print(f\"f1* mean: {f1_star}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## MSL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "origin_file_list = os.listdir(\"../../processed/MSL\")\n",
    "file_name_set = set()\n",
    "for origin_file in origin_file_list:\n",
    "    file_name_set.add(origin_file.split(\"_\")[0])\n",
    "file_name_list = list(file_name_set)\n",
    "file_name_list.sort()\n",
    "datas = {}\n",
    "for file_name in file_name_list:\n",
    "    train_data, test_data, labels = load_dataset(\"MSL\", file_name)\n",
    "    datas[file_name] = (train_data, test_data, labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C-1\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1511, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1302.065200805664 train_loss:-123.4677963256836\n",
      "score :(2225, 55) recon_mean:(2225, 55) z:(2225, 3)\n",
      "C-2\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(535, 55)\n",
      "score :(2012, 55) recon_mean:(2012, 55) z:(2012, 3)\n",
      "D-14\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(2573, 55)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch:3/5 step:100 valid_loss:-1001.688850402832 train_loss:-132.4042510986328\n",
      "score :(2586, 55) recon_mean:(2586, 55) z:(2586, 3)\n",
      "D-15\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1452, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1251.2697067260742 train_loss:-124.4929428100586\n",
      "score :(2119, 55) recon_mean:(2119, 55) z:(2119, 3)\n",
      "D-16\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1016, 55)\n",
      "score :(2152, 55) recon_mean:(2152, 55) z:(2152, 3)\n",
      "F-4\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1571, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1338.625617980957 train_loss:-132.9025115966797\n",
      "score :(3383, 55) recon_mean:(3383, 55) z:(3383, 3)\n",
      "F-5\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1819, 55)\n",
      "epoch:4/5 step:100 valid_loss:-1643.5252532958984 train_loss:-133.87457275390625\n",
      "score :(3883, 55) recon_mean:(3883, 55) z:(3883, 3)\n",
      "F-7\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1758, 55)\n",
      "epoch:4/5 step:100 valid_loss:-1758.09130859375 train_loss:-141.13308715820312\n",
      "score :(5015, 55) recon_mean:(5015, 55) z:(5015, 3)\n",
      "F-8\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(2340, 55)\n",
      "epoch:3/5 step:100 valid_loss:-2147.7251510620117 train_loss:-131.6459197998047\n",
      "score :(2448, 55) recon_mean:(2448, 55) z:(2448, 3)\n",
      "M-1\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1547, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1337.506088256836 train_loss:-123.55048370361328\n",
      "score :(2238, 55) recon_mean:(2238, 55) z:(2238, 3)\n",
      "M-2\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1546, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1287.3023071289062 train_loss:-120.93001556396484\n",
      "score :(2238, 55) recon_mean:(2238, 55) z:(2238, 3)\n",
      "M-3\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1426, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1054.3821258544922 train_loss:-111.34504699707031\n",
      "score :(2088, 55) recon_mean:(2088, 55) z:(2088, 3)\n",
      "M-4\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1454, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1226.389015197754 train_loss:-116.80995178222656\n",
      "score :(1999, 55) recon_mean:(1999, 55) z:(1999, 3)\n",
      "M-5\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1423, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1000.4828796386719 train_loss:-113.60649871826172\n",
      "score :(2264, 55) recon_mean:(2264, 55) z:(2264, 3)\n",
      "M-6\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1096, 55)\n",
      "score :(2010, 55) recon_mean:(2010, 55) z:(2010, 3)\n",
      "M-7\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1111, 55)\n",
      "score :(2117, 55) recon_mean:(2117, 55) z:(2117, 3)\n",
      "P-10\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(3016, 55)\n",
      "epoch:3/5 step:100 valid_loss:-2686.695213317871 train_loss:-129.35116577148438\n",
      "epoch:5/5 step:200 valid_loss:-3760.3758087158203 train_loss:-183.244140625\n",
      "score :(6061, 55) recon_mean:(6061, 55) z:(6061, 3)\n",
      "P-11\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(2779, 55)\n",
      "epoch:3/5 step:100 valid_loss:-2217.4130363464355 train_loss:-140.3724822998047\n",
      "epoch:5/5 step:200 valid_loss:-2146.049798965454 train_loss:-185.63975524902344\n",
      "score :(3496, 55) recon_mean:(3496, 55) z:(3496, 3)\n",
      "P-14\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(2016, 55)\n",
      "epoch:4/5 step:100 valid_loss:-1671.014778137207 train_loss:-127.1635971069336\n",
      "score :(6061, 55) recon_mean:(6061, 55) z:(6061, 3)\n",
      "P-15\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(2578, 55)\n",
      "epoch:3/5 step:100 valid_loss:-2247.216957092285 train_loss:-128.47836303710938\n",
      "score :(2817, 55) recon_mean:(2817, 55) z:(2817, 3)\n",
      "S-2\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(649, 55)\n",
      "score :(1788, 55) recon_mean:(1788, 55) z:(1788, 3)\n",
      "T-12\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(802, 55)\n",
      "score :(2391, 55) recon_mean:(2391, 55) z:(2391, 3)\n",
      "T-13\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(802, 55)\n",
      "score :(2391, 55) recon_mean:(2391, 55) z:(2391, 3)\n",
      "T-4\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1591, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1437.756721496582 train_loss:-138.6772003173828\n",
      "score :(2178, 55) recon_mean:(2178, 55) z:(2178, 3)\n",
      "T-5\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(1591, 55)\n",
      "epoch:5/5 step:100 valid_loss:-1400.0469818115234 train_loss:-126.00099182128906\n",
      "score :(2179, 55) recon_mean:(2179, 55) z:(2179, 3)\n",
      "T-8\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(524, 55)\n",
      "score :(1480, 55) recon_mean:(1480, 55) z:(1480, 3)\n",
      "T-9\n",
      "self._valid_step_freq:100\n",
      "AE_layer 55 3 16 16\n",
      "AE_layer 3 55 16 16\n",
      "(308, 55)\n",
      "score :(1057, 55) recon_mean:(1057, 55) z:(1057, 3)\n"
     ]
    }
   ],
   "source": [
    "results = {}\n",
    "for machine in file_name_list:\n",
    "        print(machine)\n",
    "        train_data,test_data, labels = datas[machine]\n",
    "        model = OmniAnomaly(x_dims=train_data.shape[1], window_size=40,max_epochs=5, valid_step_frep=100, batch_size=64)\n",
    "        model.fit([train_data])\n",
    "        score,_,_,_= model.predict(test_data)\n",
    "        anomaly_score = -np.mean(score, axis=1)\n",
    "        result = bf_search(score=anomaly_score.squeeze(), label=labels[:-39].squeeze(), verbose=False)\n",
    "        results[machine] = result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "precision mean: 0.8262\n",
      "recall mean: 0.95\n",
      "f1 mean: 0.8624\n",
      "f1* mean: 0.8838\n"
     ]
    }
   ],
   "source": [
    "f1_scores = [item['f1-score'] for item in list(results.values())]\n",
    "precisions = [item['precision'] for item in list(results.values())]\n",
    "recalls = [item['recall'] for item in list(results.values())]\n",
    "TNs = [item['TN'] for item in list(results.values())]\n",
    "TPs = [item['TP'] for item in list(results.values())]\n",
    "FNs = [item['FN'] for item in list(results.values())]\n",
    "FPs = [item['FP'] for item in list(results.values())]\n",
    "f1_mean = round(np.mean(f1_scores).item(),4)\n",
    "precision_mean = round(np.mean(precisions),4)\n",
    "recall_mean = round(np.mean(recalls),4)\n",
    "f1_star = round(2 * precision_mean * recall_mean / (precision_mean + recall_mean + 0.00001),4)\n",
    "print(f\"precision mean: {precision_mean}\")\n",
    "print(f\"recall mean: {recall_mean}\")\n",
    "print(f\"f1 mean: {f1_mean}\")\n",
    "print(f\"f1* mean: {f1_star}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "yjq-ml",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
